import { IThemeColor } from '../../../../type/index';

interface IData {
  name: string;
  value: number;
}
export interface ITwoScaleParams {
  echarts: any;
  dom: HTMLElement;
  title: string;
  labelList: string[];
  valueList: number[];
  themeColor: IThemeColor;
}

export const twoScaleChart = (props: ITwoScaleParams) => {
  let dataList = [] as IData[];

  props.labelList.forEach((item, index) => {
    dataList.push({
      name: item,
      value: props.valueList[index],
    });
  });

  const charts = props.echarts.init(props.dom);
  charts.setOption({
    // color: ['#67c23a', '#f56c6c'],
    title: [
      {
        text: props.title,
        textStyle: {
          color: props.themeColor.font,
          fontSize: 16,
          fontWeight: 'normal',
        },
        padding: [16, 0, 0, 16],
      },
    ],
    tooltip: {
      trigger: 'item',
    },
    series: [
      {
        name: props.title, //用于tooltip
        type: 'pie',
        center: ['50%', '55%'], //调节饼图位置 [x,y]
        radius: ['40%', '70%'],
        minAngle: 6,
        itemStyle: {
          borderRadius: 8,
        },
        label: {
          fontSize: 14,
          color: props.themeColor.font,
        },
        emphasis: {
          label: {
            show: true,
            fontSize: 16,
            fontWeight: 'bold',
          },
        },
        data: dataList,
      },
    ],
  });
};
